#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <unordered_set>

using namespace std;

class Solution
{
public:
    void recursionTry(vector<vector<int>> &ans, vector<int> &nums, int curIndex)
    {
        if (curIndex == nums.size())
        {
            ans.push_back(nums);
            return;
        }
        unordered_set<int> addSet;
        for (int i = curIndex; i < nums.size(); i++)
        {
            if (addSet.find(nums[i]) == addSet.end())
            {
                swap(nums[i], nums[curIndex]);
                recursionTry(ans, nums, curIndex + 1);
                swap(nums[i], nums[curIndex]);
                addSet.insert(nums[i]);
            }
        }
    }
    vector<vector<int>> permuteUnique(vector<int> &nums)
    {
        vector<vector<int>> ans;
        recursionTry(ans, nums, 0);
        return ans;
    }
};

int main()
{
    vector<int> nums{2, 2, 1};
    Solution solution{};
    solution.permuteUnique(nums);
    return 0;
}